package com.wetao.lib_common.utils;

import java.io.File;
import java.io.FileFilter;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MyFileFilter implements FileFilter {

    @Override
    public boolean accept(File pathname) {
        String filename = pathname.getName().toLowerCase();
        if(isNumeric(filename)){
            return true;
        }else{
            return false;
        }
    }

    public boolean isNumeric(String str) {
        //Pattern pattern = Pattern.compile("^-?[0-9]+"); //这个也行
        Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$");//这个也行
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}
